// LevelDataProvider.java
package com.SouthernWall_404.AgeRight.Common.API.Capability.Provider;

import com.SouthernWall_404.AgeRight.Common.API.Capability.Locks;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class LocksProvider implements ICapabilitySerializable<CompoundTag> {
    private Locks locks;

    public static final Capability<Locks> LOCKS = CapabilityManager.get(new CapabilityToken<>(){});

    private final LazyOptional<Locks> lazyOptional=LazyOptional.of(()->this.locks);

    public LocksProvider() {
        this.locks = new Locks();
    }

    @Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
        return getCapability(cap);
    }

    @Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap) {
        if(cap== LOCKS)
        {
            return LazyOptional.of(() -> locks).cast();
        }
        else
        {
            return LazyOptional.empty();
        }
    }

    @Override
    public CompoundTag serializeNBT() {
        return locks.serializeNBT();
    }

    @Override
    public void deserializeNBT(CompoundTag nbt) {
        locks.deserializeNBT(nbt);
    }
}